<template>
	<view>
		<view class="titlebox">
			<view class="trade">
				<view class="texts" :class="curr==0?'active':''" data-index="0" @tap="changeBar">动态</view>
				<view class="texts" :class="curr==1?'active':''" data-index="1" @tap="changeBar">关注</view>
			</view>
			<view v-for="(item,index) in top_tab" :key='index' :id="index" class="uni-tab-item" @click="tabTap">
				<text class="uni-tab-item-title"
					:class="toptab==index ? 'uni-tab-item-title-active' : ''">{{item}}</text>
			</view>
		</view>
		<view>
			<swiper style="height:90vh" :current="curr" @change="setCurr">
				<swiper-item class="swiper-item1">
					<scroll-view class="scroll-view1" scroll-y="true" style="height: auto"
						@scrolltolower.stop.prevent="lower">
						<view class="my_evaluate" v-for="(item,index) in recList" :key="index"
							@click.stop="dynamic(item)">
							<!--这里的list要换成获取到的数据-->
							<view class="title">
								<text>{{item.title}}</text>
								<!--帖子标题-->
							</view>
							<view class="headbox">
								<view class="head_image" @click.stop="getUser(item)">
									<!-- <image :src="item.user.avatar"></image> -->
									<image :src="item.portrait"></image>
									<!--头像-->
								</view>
								<view class="headcenter">
									<!-- <view class="head_name" @click.stop="getUser(item)">{{item.user.userName}}</view>
									<view class="head_time">{{renderTimeYMDHMS(item.postTime)}}</view> -->
									<view class="head_name" @click.stop="getUser(item)">{{item.nickname}}</view>
									<view class="head_time">{{item.createTime}}</view>
								</view>
							</view>
							<view class="content">
								<text>
									{{item.content}}
								</text>
							</view>
							<view v-if="item.topicPictures === null">
							</view>
							<view v-if="item.topicPictures !== null">
								<view class="dynamicimage" v-if="item.topicPictures.length === 1">
									<image class="image" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
								<view class="dynamicimage2" v-if="item.topicPictures.length === 2">
									<image class="image2" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
								<view class="dynamicimage4" v-if="item.topicPictures.length === 4">
									<image class="image4" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
								<view class="dynamicimage3" v-if="item.topicPictures.length === 3 || item.topicPictures.length === 5 || item.topicPictures.length === 6 || 
							item.topicPictures.length === 7 || item.topicPictures.length === 8 || item.topicPictures.length === 9">
									<image class="image3" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
							</view>


							<view class="tagbox">
								<!-- <view class="tag" v-for="(a, index) in item.postTag" :key="index"
									:style="{'background-color':colorlists[index]}">
									#{{a}}
								</view> -->

								<view class="tag" v-for="(a,index) in item.tag" :key="index"
									:style="{'background-color':colorlists[index]}">
									{{a}}
								</view>
							</view>
							
							<view class="likecmt">
								<view class="likebox">
									<view @click.stop="likeNew(item)" hover-stay-time="1000">
										<image v-if="item.isLike == false"
											src="../../static/likefalseicon.png"></image>
										<image v-if="item.isLike == true"
											src="../../static/likeorcmt/liketrueicon.png"></image>
									</view>
									<text>{{item.thumpUp}}</text><!-- {{item.postLikeNum}} -->
								</view>
								<view class="cmtbox">
									<image src="../../static/likeorcmt/resoicon.png"></image>
									<text>{{item.recommendNum}}</text>
								</view>
							</view>
							
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item1">
					<scroll-view class="scroll-view1" scroll-y="true" style="height: auto"
						@scrolltolower.stop.prevent="lower">
						<view class="my_evaluate" v-for="(item,index) in attentionList" :key="index"
							@click.stop="dynamic(item)">
							<!--这里的list要换成获取到的数据-->
							<view class="title">
								<text>{{item.title}}</text>
								<!--帖子标题-->
							</view>
							<view class="headbox">
								<view class="head_image" @click.stop="getUser(item)">
									<!-- <image :src="item.user.avatar"></image> -->
									<image :src="item.portrait"></image>
									<!--头像-->
								</view>
								<view class="headcenter">
									<!-- <view class="head_name" @click.stop="getUser(item)">{{item.user.userName}}</view>
									<view class="head_time">{{renderTimeYMDHMS(item.postTime)}}</view> -->
									<view class="head_name" @click.stop="getUser(item)">{{item.nickname}}</view>
									<view class="head_time">{{item.createTime}}</view>
								</view>
							</view>
							<view class="content">
								<text>
									{{item.content}}
								</text>
							</view>
							<view v-if="item.topicPictures === null">
							</view>
							<view v-if="item.topicPictures !== null">
								<view class="dynamicimage" v-if="item.topicPictures.length === 1">
									<image class="image" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
								<view class="dynamicimage2" v-if="item.topicPictures.length === 2">
									<image class="image2" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
								<view class="dynamicimage4" v-if="item.topicPictures.length === 4">
									<image class="image4" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
								<view class="dynamicimage3" v-if="item.topicPictures.length === 3 || item.topicPictures.length === 5 || item.topicPictures.length === 6 || 
							item.topicPictures.length === 7 || item.topicPictures.length === 8 || item.topicPictures.length === 9">
									<image class="image3" :src="pic" v-for="(pic, index) in item.topicPictures"
										mode="aspectFill" :key="index"></image>
								</view>
							</view>
				
							<view class="tagbox">
								<!-- <view class="tag" v-for="(a, index) in item.postTag" :key="index"
									:style="{'background-color':colorlists[index]}">
									#{{a}}
								</view> -->
				
								<view class="tag" v-for="(a,index) in item.tag" :key="index"
									:style="{'background-color':colorlists[index]}">
									{{a}}
								</view>
							</view>
							
							<view class="likecmt">
								<view class="likebox">
									<view @click.stop="likeNew(item)" hover-stay-time="1000">
										<image v-if="item.isLike == false"
											src="../../static/likefalseicon.png"></image>
										<image v-if="item.isLike == true"
											src="../../static/likeorcmt/liketrueicon.png"></image>
									</view>
									<text>{{item.thumpUp}}</text><!-- {{item.postLikeNum}} -->
								</view>
								<view class="cmtbox">
									<image src="../../static/likeorcmt/resoicon.png"></image>
									<text>{{item.recommendNum}}</text>
								</view>
							</view>
							
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<uni-fab  horizontal="right" vertical="bottom" direction="horizontal"
			 @fabClick="fabClick"></uni-fab>
	</view>
</template>

<script>
	export default {
		onLoad(){
			var userId = getApp().globalData.userId
			this.userId = getApp().globalData.userId
			console.log(this.userId)
			// this.getRec(this.userId)
			// this.getAttention(this.userId)
		},
		onShow() {
			this.getRec(this.userId)
			this.getAttention(this.userId)
		},
		data() {
			return {
				userId: "",
				recList: [],
				attentionList: [],
				curr: 0,
				testlist1: [1, 2, 3, 4, 5, 6],
				photolist: [1, 2, 3, 4],
				isLike: 0,
				taglist: [1,2],
				colorlists: [
					'rgb(243, 2, 168)',
					'rgb(16, 195, 195)',
					'rgb(84, 2, 255)',
					'hsl(12, 90%, 34%)',
					'hsl(138, 24%, 48%)',
					'rgb(232, 13, 131)',
					'hsl(0, 99%, 34%)',
					'rgb(226, 166, 198)',
					'hsl(278, 17%, 66%)',
					'rgb(234, 199, 12)',
					'blueviolet'
				],
				likenumber:10
			}
		},
		methods: {
			//获取综合推荐
			getRec(userId) {
				uni.request({
				    url: this.baseurl + '/getRecommendList',
					data: {
						userId: userId
					},
				    success: (res) => {
						this.recList = res.data.topicList;
						console.log(res.data.topicList);
						for(var i = 0; i < this.recList.length; i++) {
							this.recList[i].isLike = false
						}
						console.log(this.recList);
				    }
				});
			},
			//获取关注
			getAttention(userId) {
				uni.request({
				    url: this.baseurl + '/getAttentionList',
					data: {
						userId: userId
					},
				    success: (res) => {
						console.log(res.data.topicList);
						this.attentionList = res.data.topicList;
						for(var i = 0; i < this.attentionList.length; i++) {
							this.attentionList[i].isLike = false
						}
				    }
				});
			},
			likeNew(item){
				if(item.isLike == false){
					item.isLike = true;
					item.thumpUp++;
				}
				else{
					item.isLike = false;
					item.thumpUp--;
				}
			},
			fabClick() {
				// uni.showToast({
				// 	title: '点击了悬浮按钮',
				// 	icon: 'none'
				// });
				uni.navigateTo({
					url:"../post/creatpost"
				})
			},
			dynamic(item) {
				console.log('你点击了动态')
				console.log(item)
				uni.navigateTo({
					url: '../post/postdetail'
						+ '?topicId='
						+ item.topicId
					
				})
			},
			changeBar(e) {
				// console.log(e.detail.current)
				let thisCurr = e.detail.current || e.currentTarget.dataset.index || 0;
				// console.log(thisCurr)
				this.curr = thisCurr;
			},
			setCurr(e) {
				// console.log(e.detail.current)
				let thisCurr = e.detail.current || e.currentTarget.dataset.index || 0;
				// console.log(thisCurr)
				this.curr = thisCurr;

				// if (this.curr == 0) {
				// 	//动态最新
				// 	this.dynamicNewPageNumber = 0,
				// 	this.dynamicNewPageSize = 10,
				// 	this.dynamicNewStatus = 'more',
				// 	this.dynamicNewUpLoadData =  [],
				// 	this.dynamicNewListData = [],
				// 	this.dynamicNewPageLoad()
				// }
				// if (this.curr == 1) {
				// 	//动态最热
				// 	this.dynamicHotPageNumber = 0,
				// 	this.dynamicHotPageSize = 10,
				// 	this.dynamicHotStatus = 'more',
				// 	this.dynamicHotUpLoadData = [],
				// 	this.dynamicHotListData = [],
				// 	this.dynamicHotPageLoad()
				// }
				// if (this.curr == 2) {
				// 	//动态关注
				// 	this.dynamicMyPageNumber = 0,
				// 	this.dynamicMyPageSize = 10,
				// 	this.dynamicMyStatus = 'more',
				// 	this.dynamicMyUpLoadData = [],
				// 	this.dynamicMyListData = [],
				// 	this.dynamicMyPageLoad()
				// }
			},
			getUser(item) { //跳转到用户界面
				// if (item.user.userId === getApp().globalData.userId) {
				// 	uni.navigateTo({
				// 		url: "/pages/user/myhome"
				// 	})
				// } else {
				// 	uni.navigateTo({
				// 		url: "/pages/user/friendhome" +
				// 			"?userId=" +
				// 			item.user.userId
				// 	})
				// }
				// console.log('你点击了用户')
				uni.switchTab({
					url: "../user/UserMsg"
				})
			},
			//修改时间格式：年月日时分秒
			renderTimeYMDHMS(date) {
				var dateee = new Date(date).toJSON();
				return new Date(+new Date(dateee) + 8 * 3600 * 1000)
					.toISOString()
					.replace(/T/g, ' ')
					.replace(/\.[\d]{3}Z/, '')
			},
		}
	}
</script>

<style lang="scss">
	// page {
	// 	background-color: #C0E9FF;
	// }

	.titlebox {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 10vh;
		width: 100%;
		background-color: #C0E9FF;
		// position: fixed;
		// margin-top: 100rpx;

		.trade {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			text-align: center;
			//background-color: #007AFF;
			width: 295rpx;
			color: #FFFFFF;
			overflow: auto;
			font-size: 40rpx;
		}

		.trade view {
			margin-top: 20rpx;
			text-align: center;
			padding-left: 10upx;
			width: 30%;
			float: left;
		}

		.trade .texts.active {
			margin-top: 23rpx;
			//border-bottom: 8upx solid #007AFF;
			font-size: 45rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
	}

	.swiper-item1 {
		background-color: #F9F9F9;
		display: flex;

		.scroll-view1 {
			height: 100%;

			.my_evaluate {
				display: flex;
				flex-direction: column;
				padding: 20rpx;
				margin: 20rpx;
				border-radius: 8rpx;
				box-shadow: 0 0 10rpx 2rpx rgba($color: #000000, $alpha: 0.1);
				box-sizing: border-box;
				background: #FFFFFF;

				.title {
					width: 100%;
					//background-color: #2C405A;

					text {
						font-weight: bold;
						font-size: 35rpx;
					}
				}

				.headbox {
					display: flex;
					flex-direction: row;
					float: left;
					width: 100%;
					height: 140rpx;
					justify-content: space-between;
					align-items: center;
					position: relative;
					justify-content: flex-start;

					.head_image {
						//background-color: #2C405A;
						width: 100rpx;
						height: 100rpx;
						//overflow: hidden;
						margin-left: 10rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
					}

					.headcenter {
						display: flex;
						//background-color: #4CD964;
						height: 120rpx;
						flex-direction: column;
						width: 400rpx;
						margin-left: 10rpx;

						.head_name {
							//background-color: #FFFFFF;

							margin-top: 15rpx;
							font-size: 35rpx;
							color: #555555;
							//position: absolute; 
							//left: 80rpx;
							font-weight: bold;
						}

						.head_time {
							//background-color: #FFFFFF;

							margin-top: 15rpx;
							font-size: 30rpx;
							color: #999999;
						}
					}
				}

				.content {
					//background-color: #FFFFFF;
					//background-color: #007111;
					//display: flex;
					width: 630rpx;
					font-size: 25rpx;
					justify-content: center;
					//align-items: center;
					color: #555555;
					margin-left: 20rpx;
					overflow: hidden;
					word-break: break-all;
					text-overflow: ellipsis;
					display: -webkit-box;
					/** 对象作为伸缩盒子模型显示 **/
					-webkit-box-orient: vertical;
					/** 设置或检索伸缩盒对象的子元素的排列方式 **/
					-webkit-line-clamp: 5;
					//align-items: center;
				}

				.dynamicimage {
					display: flex;
					//background-color: #000000;
					flex-direction: row;
					//align-items: center;
					justify-content: center;
					margin-top: 20rpx;

					.image {

						align-items: center;
						height: 400rpx;
						width: 400rpx;
						border-radius: 10rpx;
					}
				}

				.dynamicimage2 {
					display: flex;
					//background-color: #000000;
					flex-direction: row;
					align-items: center;
					justify-content: center;
					margin-top: 20rpx;

					.image2 {
						//background-color: #007AFF;
						align-items: center;
						height: 300rpx;
						width: 300rpx;
						border-radius: 10rpx;
						margin-left: 10rpx;
					}
				}

				.dynamicimage3 {
					display: flex;
					//background-color: #000000;
					flex-wrap: wrap;
					flex-direction: row;
					align-items: center;
					//justify-content: center;
					align-items: flex-start;
					align-content: flex-start;
					margin-top: 20rpx;
					margin-left: 15rpx;

					.image3 {
						//background-color: #007AFF;
						align-items: center;
						height: 200rpx;
						width: 200rpx;
						border-radius: 10rpx;
						margin-left: 10rpx;
						margin-top: 10rpx;
					}
				}


				.dynamicimage4 {
					display: flex;
					//background-color: #000000;
					flex-wrap: wrap;
					flex-direction: row;
					align-items: flex-start;
					align-content: flex-start;
					justify-content: center;
					margin-top: 10rpx;

					.image4 {
						//background-color: #007AFF;
						margin-top: 10rpx;
						align-items: center;
						height: 300rpx;
						width: 300rpx;
						border-radius: 10rpx;
						margin-left: 10rpx;
					}
				}

				.tagbox {
					display: flex;
					flex-direction: row;
					height: 50rpx;
					width: 100%;
					//background-color: #007AFF;
					margin-top: 15rpx;
					justify-content: flex-start;
					align-items: center;

					.tag {
						display: flex;
						font-size: 20rpx;
						margin-left: 20rpx;
						padding-top: 5rpx;
						padding-bottom: 10rpx;
						padding-left: 10rpx;
						padding-right: 10rpx;
						color: #FFFFFF;
						height: 30rpx;
						border-radius:20rpx;
						//align-items: center;
						//width: 100rpx;
						text-align: center;
						text-justify: center;
					}
				}
				
				.likecmt {
					margin-top: 30rpx;
					//background-color: #007AFF;
					height: 60rpx;
					width: 100%;
					display: flex;
					//flex: 1;
					//width: 200rpx;
					//margin-left: 200rpx;
					justify-content: flex-end;
				
					.likebox {
						display: flex;
						flex-direction: row;
						//background-color: #333333;
						height: 100%;
						width: 120rpx;
				
						image {
							height: 50rpx;
							width: 50rpx;
						}
				
						text {
							margin-top: 5rpx;
						}
					}
				
					.cmtbox {
						display: flex;
						flex-direction: row;
						//background-color: #4CD964;
						height: 100%;
						width: 120rpx;
					}
				
					image {
						height: 50rpx;
						width: 50rpx;
					}
				
					text {
						margin-top: 5rpx;
					}
				}
			}
		}
	}

	.swiper-item2 {
		background-color: #F9F9F9;
		display: flex;

		.scroll-view2 {
			height: 100%;
		}
	}
</style>
